package com.tojabo.swing.fourteen_table;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTable;

public class JMenuItemDemo1 {
	private static final long serialVersionUID = 1L;
	static final int WIDTH = 600;
	static final int HEIGHT = 300;
	JFrame f;
	private JMenuBar menubar;
	JMenuItem item1;
	static JPanel p;
	JTable table;

	public JMenuItemDemo1() {

		f=new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		menubar = new JMenuBar();//菜单栏  
        f.setJMenuBar(menubar); 
        
        JMenu menu = new JMenu("ni");
        menubar.add(menu);
         item1 = new JMenuItem("click me");
         menu.add(item1);
		
		// 与上一章中如何定义个性化菜单一节中实例中的创建菜单步骤内容相同
		Object[][] playerInfo = {
				{ "王鹏", new Integer(91), new Integer(1949), new Integer(1910) },
				{ "朱雪莲", new Integer(82), new Integer(1969), new Integer(1510) },
				{ "梅庭", new Integer(47), new Integer(1957), new Integer(1040) },
				{ "赵龙", new Integer(61), new Integer(1957), new Integer(1180) },
				{ "李兵", new Integer(90), new Integer(1987), new Integer(1770) }, };
		String[] Names = { "姓名", "工号", "出生年月", "薪水" };
		table = new JTable(playerInfo, Names);
		table.setPreferredScrollableViewportSize(new Dimension(850, 300));
		item1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent Event) {
				table.setPreferredScrollableViewportSize(new Dimension(850, 300));
				p.add(table.getTableHeader(), BorderLayout.NORTH);
				p.add(table, BorderLayout.CENTER);
			}
		});
	}

	public static void main(String args[]) {
		new JMenuItemDemo1();
	}
}
